﻿#region using...
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
#endregion

namespace Infusion.Silverlight.Controls.Ribbon
{
    #region : RibbonLabel :
    #region Template Parts...
    [TemplatePart(Name = RibbonLabel.RibbonLabelLayoutRoot, Type = typeof(Grid))]
    [TemplatePart(Name = RibbonLabel.TxtText, Type = typeof(TextBlock))]
    #endregion
    public class RibbonLabel : RibbonTabGroupItem
    {
        #region TemplatePart Names...
        public const string RibbonLabelLayoutRoot = "RibbonLabelLayoutRoot";
        public const string TxtText = "TxtText";
        #endregion

        #region TemplatePart Variables...
        private Grid ribbonLabelLayoutRoot;
        private TextBlock txtText;
        #endregion

        #region Class Variables...
        private bool templateApplied = false;
        #endregion

        #region Dependency Properties...
        #region TextProperty
        /// <summary>
        /// Identifies the Infusion.Silverlight.Controls.Ribbon.RibbonLabel.Text dependency property.
        /// </summary>
        public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
                "Text",
                typeof(string),
                typeof(RibbonLabel),
                new PropertyMetadata(new PropertyChangedCallback(TextPropertyChanged)));
        #endregion
        #endregion

        #region Dependency Property Changed Handlers...
        #region TextPropertyChanged
        private static void TextPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
        }
        #endregion
        #endregion

        #region Constructor(s)...
        public RibbonLabel() : base()
        {
            DefaultStyleKey = typeof(RibbonLabel);
        }
        #endregion

        #region Methods...
        #region OnApplyTemplate
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (!templateApplied)
            {
                ribbonLabelLayoutRoot = (Grid)GetTemplateChild(RibbonLabelLayoutRoot);
                txtText = (TextBlock)GetTemplateChild(TxtText);

                if (!string.IsNullOrEmpty(Text))
                    txtText.Text = Text;

                templateApplied = true;
            }
        }
        #endregion
        #endregion

        #region Properties...
        #region Text
        public string Text
        {
            get { return (string)GetValue(TextProperty); }
            set { SetValue(TextProperty, value); }
        }
        #endregion
        #endregion
    }
    #endregion
}